/**************工具函数**************/
// 在.vue页面模块导入 import {} from '../utils/utils.js'

export const getImgUrl = (src) => {
	return require('@/assets/' + src);
}

/**
 * @Description: 
 * [通过参数名获取url中的参数值]
 * 示例URL:http://htmlJsTest/getrequest.html?uid=admin&rid=1&fid=2&name=小明
 * @param  {[string]} queryName [参数名]
 * @return {[string]}           [参数值]
 */
export const getQueryValue = (queryName) => {
	var reg = new RegExp("(^|&)" + queryName + "=([^&]*)(&|$)", "i");
	var r = window.location.search.substr(1).match(reg);
	if (r != null) {
		return decodeURI(r[2]);
	} else {
		return null;
	}
};

/**
 * @Description: 
 * 平滑滚动
 * @rate {number} 速率
 * @pos {number} 滚动距离
 * @el {element} 滚动对象
 */
export const somoothMove = (rate, pos, el) => {
	var scrollTop = el.scrollTop;

	var move = function() {
		// 临界判断，终止动画
		if (Math.abs(el.scrollTop - pos) <= 1) {
			el.scrollTop = pos;
			return;
		}
		scrollTop = scrollTop + (pos - scrollTop) / rate;
		el.scrollTop = scrollTop;
		requestAnimationFrame(move);
	};
	move();
};
